/**
 * 定义站点信息管理模块
 */
(function(window, angular, undefined){
	var Module = angular.module('water.apps.WasteGas.gyfqQyManager.gyfqInfo.monitorStationManager', ['water.entity.monitorStation',
	                                                                                          'water.apps.common.stationInfo.monitorStationManager']);
	
	Module.controller('fqStationManagerController',function($rootScope,$scope,$monitorStationService,$controller){
		/**
		 * 选择的工业污染id
		 */
		$scope.COMPANY_CODE;
		var control = $controller("commonStationManagerController",{$scope:$scope});
		$scope.dataPramChangedBroadCast();
		/**
		 * 监听站点列表点击事件
		 */
		if($wdp.viewValue.wwtpDetailParmWatch){
			$wdp.viewValue.wwtpDetailParmWatch();
		}
		$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
			if(!$wdp.viewValue.wwtpDetailParm){
				return;
			}
			if($wdp.viewValue.wwtpDetailParm.COMPANY_CODE){
			$scope.COMPANY_CODE = $wdp.viewValue.wwtpDetailParm.COMPANY_CODE;
			$scope._getStationsList($scope.COMPANY_CODE);
			}
        },true);
		/**
		 * 提交编辑按钮点击事件
		 */
		$scope.onSubmitEditClick = function(data){
			$monitorStationService.updateModel(data).then(function(){
				$.messager.alert("保存成功","保存成功",'info');
				$scope._getStationsList($scope.COMPANY_CODE);
				$scope.editDialog.close();
			});
		}
		/**
		 * 获取站点列表
		 */
		$scope._getStationsList= function(WWTPID){
			$monitorStationService.getList({'WWTP_ID':WWTPID}).then(function(d){
				$scope.stations = d
			});
		}
		
		/**
		 * 提交新建按钮点击事件
		 */
		$scope.onSubmitCreateClick = function(data){
			//目前很多左侧的联动都还是通过code来标识站点，所以入库的时候必须负值code.
			data.CODE=data.EXP_NO;
			//新建站点时，必须对wwtp_id进行赋值,增加企业从属关系
			data.WWTP_ID=$scope.COMPANY_CODE;
			//默认点位都为已建
			data.BUILD_STATUS='0';
			//默认点位都为废气点位
			data.STATION_CATEGORY='4'; 
			$monitorStationService.createModel(data).then(function(){
				$.messager.alert("保存成功","保存成功",'info');
				$scope.createDialog.close();
				//更新所属站点
				$scope._getStationsList($scope.COMPANY_CODE);
			});
		}
	});
}(window, angular));	